package pzl.com.mvp.presenter;

import pzl.com.mvp.model.UserModel;
import pzl.com.mvp.model.interfaces.ILoginInteractor;
import pzl.com.mvp.model.interfaces.IUserModel;
import pzl.com.mvp.presenter.interfaces.ILoginPresenter;
import pzl.com.mvp.view.interfaces.ILoginView;

/**
 * Created by Administrator on 2016-04-12.
 */
public class LoginPresenterImp implements ILoginPresenter {
    private ILoginView iLoginView;
    private ILoginInteractor iLoginInteractor;
    private IUserModel iUserModel;

    public LoginPresenterImp(ILoginView iLoginView, ILoginInteractor iLoginInteractor, IUserModel iUserModel) {
        this.iLoginView = iLoginView;
        this.iLoginInteractor = iLoginInteractor;
        this.iUserModel = iUserModel;
    }

    @Override
    public boolean verifyLogin() {
        return iLoginInteractor.login(iLoginView.getName(), iLoginView.getPwd());
    }

    @Override
    public void saveUser() {
        iUserModel.setName(iLoginView.getName());
        iUserModel.setPwd(iLoginView.getPwd());
        ((UserModel) iUserModel).toString();
    }

    @Override
    public UserModel getUser() {
        UserModel userModel = new UserModel(iUserModel.getName(), iUserModel.getPwd());
        return userModel;
    }
}
